home *** CD-ROM | disk | FTP | other *** search
- -------------------------[ WI.LIB ]----------for OS/2--------------------------
- WI.LIB - Wilkes Index Library
- Copyright (c) 1989 by Roger Wilkes
- Member: Association of Shareware Professionals (ASP)
- Cost of this Software $40; Gov./Ed. $30
- Wilkes Software, inc.
- Memphis, TN 38134
- or Register on BBS at (901)377-5608
- -------------------------------------------------------------------------------
-
- There are a total of six (6) function calls available with this library.
- 1) IX_add - to add keys to an index file
- 2) IX_del - to delete keys from an index file
- 3) IX_find_first - to find the first key which meets comparison criteria
- 4) IX_find_last - to find the last key which meets comparison criteria
- 5) IX_find_next - to find the next key
- 6) IX_find_prev - to find the previous key
-
- -------------------------------------------------------------------------------
-
- You must insure that "WI.LIB" is available to the linker at link time.
- This library is meant to be linked with Microsoft large (-AL) or huge (-AH)
- memory models.
-
- Place WI.LIB in your LIB directory and place INDEX.H in your INCLUDE
- directory.
-
- The maximum char array key length is 127. All data types other than this
- one can use the "data_type" defines (see INDEX.H). The character array
- data type is formed by anding the length and 0x80.
-
- -------------------------------------------------------------------------------
-
- 1) Adding a new key to the index file:
- Indexing/Reindexing a file:
-
- int IX_add (long file_pos,
- char *key_addr,
- unsigned char data_type,
- int file_handle);
-
- file_pos - is the piece of data which will accompany the key. This
- information will be returned to you when you use the
- IX_find_xxxxx function calls. If you are working with
- fixed length records this can be a record length. If you
- use this field to contain a record number, you will have
- to do multiplications to get it to a byte position within
- the file you are indexing. You may simply use this field
- to contain the byte position of the record being indexed.
- key_addr - contains the address of either
- 1) the key data
- 2) a KEY_STRUCT (see INDEX.H) structure containing up to
- 10 key parts. The order of importance of the key
- fields is from lowest index to highest (i.e.
- KEY_COMPONENT.key[0] to KEY_COMPONENT.key[9]).
- data_type - specifies that the "key_value" above is either key data
- or a KEY_STRUCT structure (see INDEX.H). If data_type
- designates key data, the length (in bytes) is also known.
-
- RETURNS: One of the function returns shown in INDEX.H
- OK where no errors were detected
- IX_IO_ERR
- IX_ERR
- INV_PARAM
- INV_NUM_KEYS
-
- EXAMPLE: if we have a file with the following record layout which we
- wish to index on the last_name
-
- -------------------------------------------------------------------------------
- /* using the Microsoft "C" Optimizing compiler */
- #include <index.h> /* after placing in include dir */
- #include <fcntl.h>
- #include <sys\types.h>
- #include <sys\stat.h>
- #include <io.h>
- #include <stdlib.h>
- #include <stdio.h>
-
- #define TRUE 1
- #define FALSE 0
-
- int nad_file;
- int index_file;
-
- int num_bytes;
- int err;
- long file_pos = 0L;
-
- struct {
- char first_name [15];
- char last_name [15];
- char addr [30];
- char city [20];
- char state [2];
- char zip [9];
- } name_and_addr;
-
- #include <os2.h>
-
- #define _NOEXIST_FAIL 0x00
- #define _NOEXIST_CREATE 0x10
- #define _EXIST_FAIL 0x00
- #define _EXIST_OPEN 0x01
- #define _EXIST_CREATE 0x02
-
- #define Close(f) (errno = DosClose (f))
- #define Lseek(f,p,o,l) (errno = DosChgFilePtr (f, p, o, &l))
- #define Read(f,b,l,s) (errno = DosRead (f, b, l, &s))
- #define Write(f,b,l,s) (errno = DosWrite (f, b, l, &s))
-
- int act_cod;
-
- main ()
- {
- if (DosOpen ("nameaddr.fil", &nad_file, &act_cod, 0L, 0,
- _NOEXIST_CREATE | _EXIST_OPEN, 0x112, 0L))
- {
- /* do something about the error */
- }
- if (DosOpen ("nameaddr.inx", &index_file, &act_cod, 0L, 0,
- _NOEXIST_CREATE | _EXIST_OPEN, 0x112, 0L))
- {
- /* do something about the error */
- }
- while (TRUE)
- {
- Read (nad_file, (char *)&name_and_addr,
- sizeof(name_and_addr), num_bytes);
- if (num_bytes == 0) /* end of file */
- break;
- if (num_bytes != sizeof(name_and_addr))
- {
- /* take care of short read */
- }
- err = IX_add (file_pos, name_and_addr.last_name,
- sizeof(name_and_addr.last_name)+0x80, index_file);
- /* 0x80 is simply the high order bit
- of the data_type. For all other data
- types you can use the #define names
- (see INDEX.H) */
- switch (err)
- {
- case OK:
- printf ("NAME: %15.15s indexed\n",
- name_and_addr.last_name);
- break;
- case IX_IO_ERR:
- printf ("IO Error on \"nameaddr.inx\" file\n");
- break;
- case IX_ERR:
- printf ("Index File is corrupted\n");
- break;
- case INV_PARAM:
- printf ("Function Call Parameters don't match\n");
- printf (" information already in \"nameaddr.inx\"\n");
- break;
- case INV_NUM_KEYS:
- printf ("The number of key fields does not match\n");
- printf (" information already in \"nameaddr.inx\"\n");
- break;
- default: break;
- }
- if (err)
- break;
- file_pos += sizeof(name_and_addr);
- }
- }
- -------------------------------------------------------------------------------
-
- 2) Deleting an index entry from an index file:
-
- int IX_del (char *key_addr,
- long file_pos,
- unsigned char data_type,
- int file_handle);
-
- key_addr - contains the address of either
- 1) the key data
- 2) a KEY_STRUCT (see INDEX.H) structure containing up to
- 10 key parts. The order of importance of the key
- fields is from lowest index to highest (i.e.
- KEY_COMPONENT.key[0] to KEY_COMPONENT.key[9]).
- file_pos - is the piece of data which will accompany the key. This
- information will be returned to you when you use the
- IX_find_xxxxx function calls. If you are working with
- fixed length records this can be a record length. If you
- use this field to contain a record number, you will have
- to do multiplications to get it to a byte position within
- the file you are indexing. You may simply use this field
- to contain the byte position of the record being indexed.
- The file position field is required in the delete to
- differentiate between duplicate keys and must be the same
- as used during IX_add.
- data_type - specifies that the "key_value" above is either key data
- or a KEY_STRUCT structure (see INDEX.H). If data_type
- designates key data, the length (in bytes) is also known.
-
- RETURNS: One of the function returns shown in INDEX.H
- OK where no errors were detected
- IX_IO_ERR
- IX_ERR
- INV_PARAM
- INV_NUM_KEYS
-
- EXAMPLE: if we have a file with the following record layout which we
- wish to delete all indexes from. NOTE: we could accomplish
- the same thing, in this case, by deleting the file; except
- here, the file size will not change (i.e. not be clean).
-
- -------------------------------------------------------------------------------
- /* using the Microsoft "C" Optimizing compiler */
- #include <index.h> /* after placing in include dir */
- #include <fcntl.h>
- #include <sys\types.h>
- #include <sys\stat.h>
- #include <io.h>
- #include <stdlib.h>
- #include <stdio.h>
-
- int nad_file;
- int index_file;
-
- int num_bytes;
- int err;
- long file_pos = 0L;
-
- struct {
- char first_name [15];
- char last_name [15];
- char addr [30];
- char city [20];
- char state [2];
- char zip [9];
- } name_and_addr;
-
- #include <os2.h>
-
- #define _NOEXIST_FAIL 0x00
- #define _NOEXIST_CREATE 0x10
- #define _EXIST_FAIL 0x00
- #define _EXIST_OPEN 0x01
- #define _EXIST_CREATE 0x02
-
- #define Close(f) (errno = DosClose (f))
- #define Lseek(f,p,o,l) (errno = DosChgFilePtr (f, p, o, &l))
- #define Read(f,b,l,s) (errno = DosRead (f, b, l, &s))
- #define Write(f,b,l,s) (errno = DosWrite (f, b, l, &s))
-
- int act_cod;
-
- main ()
- {
- if (DosOpen ("nameaddr.fil", &nad_file, &act_cod, 0L, 0,
- _NOEXIST_CREATE | _EXIST_OPEN, 0x112, 0L))
- {
- /* do something about the error */
- }
- if (DosOpen ("nameaddr.inx", &index_file, &act_cod, 0L, 0,
- _NOEXIST_CREATE | _EXIST_OPEN, 0x112, 0L))
- {
- /* do something about the error */
- }
- while (TRUE)
- {
- Read (nad_file, (char *)&name_and_addr,
- sizeof(name_and_addr), num_bytes);
- if (num_bytes == 0) /* end of file */
- break;
- if (num_bytes != sizeof(name_and_addr))
- {
- /* take care of short read */
- }
- err = IX_del (name_and_addr.last_name, file_pos,
- sizeof(name_and_addr.last_name)+0x80, index_file);
- /* 0x80 is simply the high order bit
- of the data_type. For all other data
- types you can use the #define names
- (see INDEX.H) */
- switch (err)
- {
- case OK:
- printf ("NAME: %15.15s index Deleted\n",
- name_and_addr.last_name);
- break;
- case IX_IO_ERR:
- printf ("IO Error on \"nameaddr.inx\" file\n");
- break;
- case IX_ERR:
- printf ("Index File is corrupted\n");
- break;
- case INV_PARAM:
- printf ("Function Call Parameters don't match\n");
- printf (" information already in \"nameaddr.inx\"\n");
- break;
- case INV_NUM_KEYS:
- printf ("The number of key fields does not match\n");
- printf (" information already in \"nameaddr.inx\"\n");
- break;
- default: break;
- }
- if (err)
- break;
- file_pos += sizeof(name_and_addr);
- }
- }
- -------------------------------------------------------------------------------
-
- 3) Finding indexed keys in an index file:
-
- int IX_find_first (FIND_IX *fix,
- char *key_addr,
- int find_condition,
- int file_handle,
- unsigned char data_type);
-
- int IX_find_last (FIND_IX *fix,
- char *key_addr,
- int find_condition,
- int file_handle,
- unsigned char data_type);
-
- int IX_next (FIND_IX *fix);
-
- int IX_prev (FIND_IX *fix);
-
- fix - is the address of the FIND_IX structure
- typedef struct
- {
- long data_rec; /* returned file pos */
- long recno[3]; /* used internally */
- int ix[3]; /* used internally */
- unsigned char data_type; /* used internally */
- unsigned char find_type; /* used internally */
- VALUE *val /* used internally */
- int fn; /* used internally */
- } FIND_IX;
- the data_rec field contains the file position of the
- indexed file, in order to locate the proper record.
- key_addr - contains the address of either
- 1) the key data
- 2) a KEY_STRUCT (see INDEX.H) structure containing up to
- 10 key parts. The order of importance of the key
- fields is from lowest index to highest (i.e.
- KEY_COMPONENT.key[0] to KEY_COMPONENT.key[9]).
- You must insure that the value this address points to
- does not change between IX_find_first/IX_find_last
- calls and IX_find_next/IX_find_prev calls.
- find_condition- is one of the file conditions listed in INDEX.H
- 1) FIND_EQL
- 2) FIND_GTR
- 3) FIND_LSS
- 4) FIND_NEQ
- 5) FIND_GEQ
- 6) FIND_LEQ
- file_handle - is the file number of the open file in which the indexes
- will be found.
- data_type - specifies that the "key_value" above is either key data
- or a KEY_STRUCT structure (see INDEX.H). If data_type
- designates key data, the length (in bytes) is also known.
-
- EXAMPLE: if we have a file with the following record layout which we
- wish find and print all records where the last name is
- greater than or equal to "Marty" - remember that upper and
- lower case are different:
-
- -------------------------------------------------------------------------------
- /* using the Microsoft "C" Optimizing compiler */
- #include <index.h> /* after placing in include dir */
- #include <fcntl.h>
- #include <sys\types.h>
- #include <sys\stat.h>
- #include <io.h>
- #include <stdlib.h>
- #include <stdio.h>
-
- int nad_file;
- int index_file;
-
- int num_bytes;
- int err;
- long file_pos = 0L;
- FIND_IX fix;
- char *compare_field = "Marty ";
-
- struct {
- char first_name [15];
- char last_name [15];
- char addr [30];
- char city [20];
- char state [2];
- char zip [9];
- } name_and_addr;
-
- #include <os2.h>
-
- #define _NOEXIST_FAIL 0x00
- #define _NOEXIST_CREATE 0x10
- #define _EXIST_FAIL 0x00
- #define _EXIST_OPEN 0x01
- #define _EXIST_CREATE 0x02
-
- #define Close(f) (errno = DosClose (f))
- #define Lseek(f,p,o,l) (errno = DosChgFilePtr (f, p, o, &l))
- #define Read(f,b,l,s) (errno = DosRead (f, b, l, &s))
- #define Write(f,b,l,s) (errno = DosWrite (f, b, l, &s))
-
- int act_cod;
-
- main ()
- {
- if (DosOpen ("nameaddr.fil", &nad_file, &act_cod, 0L, 0,
- _NOEXIST_FAIL | _EXIST_OPEN, 0x112, 0L))
- {
- /* do something about the error */
- }
- if (DosOpen ("nameaddr.inx", &index_file, &act_cod, 0L, 0,
- _NOEXIST_FAIL | _EXIST_OPEN, 0x112, 0L))
- {
- /* do something about the error */
- }
-
- err = IX_find_first (&fix, compare_field,
- FIND_GEQ, index_file,
- sizeof(name_and_addr.last_name)+0x80);
- while (TRUE)
- {
- switch (err)
- {
- case OK:
- lseek (nad_file, fix.data_rec, SEEK_SET);
- Read (nad_file, (char *)&name_and_addr,
- sizeof(name_and_addr), num_bytes);
- if (num_bytes != sizeof(name_and_addr))
- {
- /* take care of short read */
- }
- printf ("NAME: %15.15s %15.15s | CITY/ST: %20.20s %2.2s\n",
- name_and_addr. first_name,
- name_and_addr. last_name,
- name_and_addr. city,
- name_and_addr. state);
- break;
- case IX_IO_ERR:
- printf ("IO Error on \"nameaddr.inx\" file\n");
- break;
- case IX_ERR:
- printf ("Index File is corrupted\n");
- break;
- case NOT_FOUND:
- printf ("No Matching Keys Found\n");
- break;
- case NO_MORE:
- printf ("No More Matching Keys Found\n");
- break;
- case INV_PARAM:
- printf ("Function Call Parameters don't match\n");
- printf (" information already in \"nameaddr.inx\"\n");
- break;
- case INV_NUM_KEYS:
- printf ("The number of key fields does not match\n");
- printf (" information already in \"nameaddr.inx\"\n");
- break;
- default: break;
- }
- if (err)
- break;
- err = IX_find_next (&fix);
- }
- }
- -------------------------------------------------------------------------------
-
- 4) Data Types:
-
- #define "C"
- ------- ---
- ftCHAR char
- ftUCHAR unsigned char
- ftSCHAR signed char
- ftUNS_INT unsigned int
- ftINT int
- ftULONG unsigned long
- ftLONG long
- ftFLOAT float
- ftDOUBLE double
- ftH_BCD_1 - 10 ------- 1 to 10 char BCD field with
- sign at front of field
- ftT_BCD_1 - 10 ------- 1 to 10 char BCD field with
- sign at end of field
- ftSTRUCT ------- multi field key where the
- location of the fields is
- specified in the KEY_STRUCT
- structure (see INDEX.H)
- -------------------------------------------------------------------------------
-
- 5) KEY_STRUCT structure for multi-field keys:
-
- typedef struct
- {
- unsigned char num_keys;
- struct
- {
- unsigned char data_type; /* data_type for this field */
- VALUE *val; /* addr of this key field */
- } key [10];
- } KEY_STRUCT;
-
- If we wish to take the following record layout and index it on
- last_name and first_name (in that order):
-
- struct {
- char first_name [15];
- char last_name [15];
- char addr [30];
- char city [20];
- char state [2];
- char zip [9];
- } name_and_addr;
-
- with
-
- KEY_STRUCT keys;
-
- the keys would populated as follows:
-
- keys. num_keys = 2;
- keys. key [0]. data_type = sizeof(name_and_addr.last_name) | 0x80;
- keys. key [0]. val = (VALUE *)name_and_addr.last_name;
- keys. key [1]. data_type = sizeof(name_and_addr.first_name) | 0x80;
- keys. key [1]. val = (VALUE *)name_and_addr.first_name;
-
- the key_addr parameter for the function calls would be "(char *)&keys"
- and the data_type parameter to the function calls would be ftSTRUCT.
-
- NOTE: that the maximum number of key fields is 10. This should be enough
- for any reasonable purpose. If you require more you can stack the
- keys in some instances (char arrays back to back can be considered
- a single field as long as the cumulative sizes are < 128 characters).
- -------------------------------------------------------------------------------
-
-
-
-
-
- LICENSE
- -------
-
- Wilkes INDEX, version 1.0, is being distributed under the "shareware" or
- user supported concept. This software is NOT free software. The use or
- reproduction of this software outside of the limits specified in this license
- agreement is prohibited.
-
- Non-registered users are granted a limited license to use this software
- for a period not to exceed thirty days. During this period they should test
- and evaluate the software to determine if it will meet their needs. The use of
- this software beyond this limited time period requires registration.
- Non-registered users are not allowed to distribute this software without the
- express written permission of Wilkes Software inc. The only exceptions to this
- distribution restriction are SYSOPS of electronic bulletin boards and
- distributors of public domain and user supported software. SYSOPS and
- software distributors must abide by the copying restrictions specified below.
-
- Registered users are granted the right to use Wilkes INDEX on only
- one computer at any time. Site licensing agreements are available for
- businesses, corporations, and government agencies. Registered users are also
- granted the right to copy and distribute Wilkes INDEX subject to the
- following conditions.
-
- Wilkes INDEX must be copied in its original unmodified form.
-
- All of the files must be included in the copy.
-
- Wilkes INDEX may not be distributed in conjunction with any other
- product without the express written consent of Wilkes Software inc.
-
-
-
-
- WARRANTY
- --------
-
- Wilkes Software makes no warranty of any kind, express or implied,
- including without limitation, any warranties of merchantability and or fitness
- for a particular purpose. Wilkes Software shall not be liable for any
- damages, whether direct, indirect, special or consequential arising from a
- failure of this software to operate in the manner desired by the user.
- Wilkes Software shall not be liable for any damage to data or property which
- may be caused directly or indirectly by use of the program.
-
- IN NO EVENT WILL Wilkes Software BE LIABLE TO YOU FOR ANY DAMAGES,
- INCLUDING ANY LOST PROFITS, LOST SAVINGS OR OTHER INCIDENTAL OR CONSEQUENTIAL
- DAMAGES ARISING OUT OF YOUR USE OR INABILITY TO USE THE PROGRAM, OR FOR ANY
- CLAIM BY ANY OTHER PARTY.
-
-
-
-
-
- REGISTRATION FEES
- -----------------
-
- The registration fee for Wilkes INDEX, version 1.0, is only $40.00, with
- quantity discount for 10 or more copies to $25.00/copy.
-
- Government and Education registration fee is only $30.00, with quantity
- discount for 10 or more copies to $20.00/copy.
-
- You may fill out and return the registration page below or register on-line
- at (901)377-5608.
-
- Future updates of the site license copy are provided as follows. The first
- update is free. All others $15.00.
-
- Prices are for a titled master copy and cover all charges including shipping.
- Licensees will be informed when updates become available and given the option
- to update at will. There is NO penalty for skipping updates.
-
-
-
-
-
- If you should require assistance in the use of the Wilkes INDEX, you
- may call the WSI BBS at (901)377-5608.
-
- If you like this software please let me know. If you have enhancements
- you would like to see in this software, please let me know those also. If you
- have complaints about the way the Wilkes INDEX functions I would even like to
- hear those.
-
- The following is a registration form. In addition to the licensing use,
- I will also use this information to correlate requests for additional
- functionality and for Wilkes Software mailing list purpose (only by Wilkes
- Software). When Wilkes Software offers other software into the shareware
- system in the future, information will be sent to registered users of the
- Wilkes INDEX. If you register a non-current version I will send the
- current version to you.
-
-
-
- to: Wilkes Software, inc.
- 5231 Longwood Drive
- Memphis, TN 38134
-
-
- Name (first) ____________________ (last) ____________________
-
- Title ___________________________________
-
- Company ___________________________________
-
- Address ___________________________________
-
- ___________________________________
-
- City _________________________ State ___ Zip code _______
-
- Where software obtained: ________________________________________
-
- Version of Wilkes INDEX for Microsoft C: 1.0
-
- System: ____________________
-
- OS/2 Version: _____
-
- Phone: (____) ____ - _____
-
- If Gov./Ed. please specify: _____________________________________
-
- COST:
-
- $40/copy; 10+ copies $25/copy
- Gov./Ed. $30/copy; 10+ copies $20/copy
-
- Tennessee Residents: sales tax is 7.75%
-
- # copies _________ x your price: ____________ + TN sales tax __________
-
- = Total _________________
-
- METHOD OF PAYMENT:
-
- VISA/MASTERCARD/CHECK: __________
-
- V/MC account #: ___________________________ Expiration Date: _________
-
- Signature: __________________________________________________
-
-